var pass = false;
var language = false;
var checkcode = false;
$(function(){
	$('.btn').bind('click', function() {
		
		if (pass && language && checkcode ) {
			submitCommit();
		} else {
			easyAlert("请填写信息");
			return false;
		}
	});
	$('#checkcode').bind('change', function() {
		checkCode();

	});
	
	$('#password').bind('change', function() {
		checkStrLength($("#password").val(), 6, 16);

	});
	$('#realName').bind('change', function() {
		chinese($("#realName").val());
	});
});
function checkCode() {
	var codeUuid = localStorage.getItem("phoneNoUUID");
	var code = $("input[name='code']").val();
	$.ajax({
		type : "POST",
		dataType : 'json',
		url : server_url + 'rest/frontUser/checkCode.do?',
		data : {
			codeUuid : codeUuid,
			code : code,
			ran: Math.random()
		},
		success : function(data) {
			if (data == 1) {
				checkcode = true;
			} else if (data == 0){
			easyAlert("验证码错误");
			checkcode = false;
			}
		}
	});
}

function checkStrLength(userPass, min, max) {// 验证密码
	if (userPass.length < min || userPass.length > max) {
		easyAlert("输入字符长度须在" + min + "-" + max + "之间!");
		return pass;
	} else {
		pass = true;
	}
}
function chinese(china) { // 验证只能是中文
	var pattern = /^[\u4e00-\u9fa5]*$/;
	if (!pattern.test(china)) {
		easyAlert("名称不能为空且必须为中文");
		return language;
	} else {
		language = true;
	}
}
function submitCommit() {
	$.ajax({
		type : 'post',
		async: false,
		dataType : 'json',
		url : server_url + 'rest/frontUser/frontUserAdd.do?token=' + token
				+ '&ran=' + Math.random(),
		data : $("#myform").serializeArray(),
		contentType : "application/x-www-form-urlencoded; charset=utf-8",
		success : function(data) {
			if (data.retCode == "0000") {	
				easyAlert("注册成功");
             document.forms[0].action="login.do";
			} else {
				easyAlert("请填写信息");
			}
		}
	});
	 return false;
}